package com.qf.common.page;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.common.constants.Constants;

import java.util.LinkedList;
import java.util.List;

/**
 * 自定义分页工具类
 */
public class PageUtils {
    public static<T> PageInfo<T> getPageList(int currentPage,QueryWrapper<T> wrapper, ServiceImpl service){
        IPage<T> page = service.page(new Page(currentPage,Constants.PAGE_SIZE),wrapper);
        int pages = (int) page.getPages();
        List<Integer> list = new LinkedList<>();
        for (int i = 1; i <= pages; i++) {
            list.add(i);
        }
        return new PageInfo<>(page.getRecords(),list);
    }

}
